fdisk 创建和维护磁盘分区命令(MBR分区方案)

您所在的位置:网站首页 linux 建立分区表的工具是 fdisk 创建和维护磁盘分区命令(MBR分区方案)

fdisk 创建和维护磁盘分区命令(MBR分区方案)

2024-07-09 12:25| 来源: 网络整理| 查看: 265

fdisk 命令用于创建和维护磁盘分区,而且fdisk只能对小于2TB的硬盘进行分区,对于大于2TB的硬盘,需要使用gdisk工具分区,换句话说,使用fdisk创建分区,只能是创建MBR分区方案。

fdisk命令语法格式如下:

fdisk [options] change partition table fdisk [options] -l list partition table(s) fdisk -s give partition size(s) in blocks Options: -b sector size (512, 1024, 2048 or 4096) -c[=] compatible mode: 'dos' or 'nondos' (default) -h print this help text -u[=] display units: 'cylinders' or 'sectors' (default) -v print program version -C specify the number of cylinders -H specify the number of heads -S specify the number of sectors per track

演示示例;

[root@master ~]# fdisk -l #列出系统的全部磁盘分区情况 Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 sectors #可知系统有一个sdb硬盘,大小为16GB Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x1f9070da Device Boot Start End Blocks Id System /dev/sdb1 2048 31457279 15727616 8e Linux LVM #sdb磁盘有1个sdb1分区,Boot有* 号的表示该分区是引导分区 Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors #可知系统有一个sda硬盘,大小为43GB Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000b133c Device Boot Start End Blocks Id System /dev/sda1 2048 4095 1024 83 Linux #sda磁盘有3个分区:sda1、sda2、sda3 /dev/sda2 * 4096 1028095 512000 83 Linux /dev/sda3 1028096 83886079 41428992 8e Linux LVM Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors #可知系统有1个sdc硬盘,大小为10GB Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0542ffc2 Device Boot Start End Blocks Id System /dev/sdc1 2048 20971519 10484736 8e Linux LVM #sdc磁盘有1个sdc1分区 Disk /dev/mapper/cl-root: 60.7 GB, 60666413056 bytes, 118489088 sectors #这个是lvm逻辑卷 Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/cl-swap: 8589 MB, 8589934592 bytes, 16777216 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@master ~]# [root@master ~]# fdisk -l /dev/sdc #查看单个磁盘的情况 Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0542ffc2 Device Boot Start End Blocks Id System /dev/sdc1 2048 20971519 10484736 8e Linux LVM fdisk命令进行硬盘分区

假如我们手动添加了一个小于2TB的硬盘,系统识别为sdc,下面我们使用fdisk命令对sdc硬盘进行分区操作,如下:

[root@master ~]# fdisk /dev/sdc #注意不要选错磁盘 Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x1a6ca3e9. Command (m for help): m #打印帮助文档 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition #删除一个分区 g create a new empty GPT partition table #创建一个新的空的GPT分区表 G create an IRIX (SGI) partition table l list known partition types #列出已知的分区类型 m print this menu #打印帮助信息 n add a new partition #n表示创建1个新分区 o create a new empty DOS partition table #创建一个新的DOS分区表 p print the partition table #打印分区表 q quit without saving changes #q表示退出且不保存 s create a new empty Sun disklabel t change a partition system id #修改分区的id u change display/entry units v verify the partition table w write table to disk and exit #w表示保存并退出 x extra functionality (experts only) Command (m for help): n #输入 n,我们开始新建一个分区 Partition type: p primary (0 primary, 0 extended, 4 free) #p表示主分区,mbr分区方案最多只能有4个主分区 e extended #e表示扩展分区,最多能有1个扩展分区,可以没有扩展分区 Select (default p): p #输入 p,我们将分区创建为主分区 Partition number (1-4, default 1): 1 #输入1,我们将分区定义为第1个分区,即sdc1 First sector (2048-20971519, default 2048): #回车保持默认即可 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): #回车保持默认即可,也可以+2G这些写 Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): p #输入p打印一下分区表,查看我们新建的分区 Device Boot Start End Blocks Id System /dev/sdc1 2048 20971519 48986076 83 Linux Command (m for help): t #输入t,我们来改变一下分区的类型 Selected partition 1 Hex code (type L to list all codes): 8e #输入8e,8e就是LVM Changed type of partition 'Linux' to 'Linux LVM' Command (m for help):w #退出并保存 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@master ~]# [root@master ~]# lsblk #再次查看磁盘信息 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 500M 0 part /boot └─sda3 8:3 0 39.5G 0 part ├─cl-root 253:0 0 46.5G 0 lvm / └─cl-swap 253:1 0 8G 0 lvm [SWAP] sdb 8:16 0 15G 0 disk └─sdb1 8:17 0 15G 0 part └─cl-root 253:0 0 46.5G 0 lvm / sdc 8:32 0 10G 0 disk └─sdc1 8:33 0 10G 0 part #多了1个sdc1分区了 sr0 11:0 1 1024M 0 rom loop0 7:0 0 4.1G 0 loop /media/iso

对sdc进行了分区,下面我们就要对分区进行格式化成指定的文件系统:

#有了分区就能在分区上创建文件系统,创建文件系统后就可以挂载使用了 mkfs.xfs /dev/sdc1 mkdir /data mount /dev/sdc1 /data 总结

1、fdisk工具分区的都是mbr分区,而且fdisk分区的硬盘大小不能超过2TB; 2、mbr分区方案一般有两种: 1)分4个主分区,因为mbr最多只能分4个主分区 2)3个主分区+1个扩展分区,这样就可以在扩展分区创建n个逻辑分区(这样就可以突破mbr方案只能分4个分区的限制了,所以这种方案最合适使用) 3、最多能有1个扩展分区,可以没有扩展分区,没有扩展分区的话那就是1)情况,即硬盘最多只能分4个主分区了; 4、因为逻辑分区是在扩展分区上创建的,所以你的全部逻辑分区的容量大小总和肯定是小于等于扩展分区的容量大小的; 5、扩展分区不能直接使用,必须在其上创建逻辑分区才能存取数据,使用lsblk命令查看你就会发现,你创建的扩展分区SIZE只有几k大小,所以这就说明扩展分区不能直接使用,而这几k其实是扩展分区保存了逻辑分区的元数据信息。 6、主分区的编号1-4,扩展分区的编号1-4,逻辑分区的编号从5开始,如果删除了扩展分区,那么该扩展分区下的逻辑分区也将被删除。 7、对一个已经挂载了的硬盘,想要重新分区的话,建议先umount再分区。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3